#include<bits/stdc++.h>
using namespace std;
int t,n,m,l,sum1,sum2,v,a[1000005],b[1000005],c[1000005],p[1000005],d[1000005],e[1000005];
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	cin>>t;
	while(t--){
		cin>>n>>m>>l>>v;
		sum1=0,sum2=m;
		for(int i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i]; 
		for(int i=1;i<=m;i++) cin>>p[i];
		sort(p+1,p+m+1);
		for(int i=1;i<=n;i++){
			if(d[a[i]]==0){
				if(a[i]<=p[m]){
					sum2--;				
					d[a[i]]=1;
				}
			}
			if(a[i]<=p[m]&&a[i]>v) sum1++;
		}
		cout<<sum1<<' '<<sum2<<endl;
	}
	return 0;
}
